import { Component, OnInit, Input } from '@angular/core';
import { ReportService } from '../../../report.service';
import { LazyLoadEvent } from 'primeng/api';
import { DynamicDialogRef, DynamicDialogConfig } from 'primeng/api';
@Component({
    selector: 'report-standard-detail',
    templateUrl: './report-standard-detail.component.html',
    styleUrls: ['./report-standard-detail.component.scss']
})
export class ReportStandardDetailComponent implements OnInit {
    report: any = {};
    reportId: number = 0;
    loading: boolean = false;
    showPaginator: boolean = false;
    pageSize: number = 10;
    totalRecords: number = 0;
    records: any[] = []; //数据记录
    headers: any[] = []; //表头
    cols: any[] = []; //列信息

    //汇总信息
    conds: any[] = [];
    constructor(
        private ref: DynamicDialogRef,
        private config: DynamicDialogConfig,
        private reportService: ReportService) {
        this.reportId = config.data.reportId;
        this.conds = config.data.conds;
    }

    ngOnInit() {
        //加载统计表头
        this.reportService.loadStatisHeaderColumns(this.reportId, 1).subscribe(data => {
            debugger
            this.headers = data.headers;
            this.cols = data.cols;
            this.loadStatisRecords(null);
        });
    }
    loadStatisRecords(conds) {
        this.loading = true;
        if (conds) {
            this.conds = conds;
        }
        //反查不进行分页，最大查询5000条
        this.reportService.loadStatisRecords(this.conds, this.reportId, 5000, 1, 1).subscribe(page => {
            this.loading = false;
            this.records = page;
            this.totalRecords = page.length;
            this.showPaginator = (this.totalRecords > this.pageSize);
        });
    }
}
